#登录页面
from time import sleep
from common.Untils import WJDriver
from selenium.webdriver.common.by import By

class WJLogin:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://8.155.1.153:8081/user/login?redirect=%2Fhome"
        self.driver = WJDriver.driver
        self.driver.get(self.url)
    #1.登录成功
    def LoginSuccess(self):
        #测试场景一：账号和密码正确
        #输入账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zzj24")
        #输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        #点击登录
        self.driver.find_element(By.CSS_SELECTOR, "#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button").click()
        #sleep(1)
    #2.登陆失败
    def LoginFailed(self):
        #测试场景二：输入正确的账号和错误的密码
        #返回上一页
        #self.driver.back()
        # 输入账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zzj24")
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234567")
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button").click()
        #sleep(1)
        #测试场景三：输入错误的账号和正确的密码
        # self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.refresh()
        # 输入账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys(WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button").click()
        #sleep(1)
        #测试场景四：输入错误的账号和错误的密码
        self.driver.refresh()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # 输入账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys(WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234567")
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button").click()
        self.driver.refresh()
# login=WJLogin()
# login.LoginSuccess()
# login.LoginFailed()